package com.hmall.searchService.config;


import com.hmall.searchService.Constants.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    //声明交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(MqConstants.ITEM_EXCHANGE,true,false);
    }
    //声明队列
    @Bean
    public Queue statusUpQueue(){
        return new Queue(MqConstants.ITEM_STATUS_UP_QUEUE,true);
    }

    @Bean
    public Queue statusDownQueue(){
        return new Queue(MqConstants.ITEM_STATUS_DOWN_QUEUE,true);
    }
    //绑定队列
    @Bean
    public Binding bindingUpQueue(Queue statusUpQueue, TopicExchange topicExchange){
        return BindingBuilder.bind(statusUpQueue).to(topicExchange).with(MqConstants.ITEM_STATUS_UP_KEY);
    }

    @Bean
    public Binding bindingDownQueue(Queue statusDownQueue, TopicExchange topicExchange){
        return BindingBuilder.bind(statusDownQueue).to(topicExchange).with(MqConstants.ITEM_STATUS_DOWN_KEY);
    }

}
